export const bubbleSort = (arr) => {

    for (let i = 0; i < arr.length; i++) {

        for (let j = 0; j < arr.length - i - 1; j++) {

            if (arr[j] > arr[j + 1]) {
                const tmp = arr[j]
                arr[j] = arr[j + 1]
                arr[j + 1] = tmp

            }
        }
    }

    return arr
}

export const bubbleSort2 = (arr) => {

    for (let i = 0; i < arr.length;) {
        let lastSwappedIndex = 0
        for (let j = 0; j < arr.length - i - 1; j++) {

            if (arr[j] > arr[j + 1]) {
                const tmp = arr[j]
                arr[j] = arr[j + 1]
                arr[j + 1] = tmp
                lastSwappedIndex = j + 1
            }
        }

        i = arr.length - lastSwappedIndex
    }

    return arr
}